using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for VersionsAdaptor.
	/// </summary>
	public class LibraryVersionsAdaptor : Adaptor, IRefreshable
	{
    private VersionCollection versions;
		public LibraryVersionsAdaptor(VersionCollection versions)
		{
      this.versions = versions;
		}

    public override void AddChildren(System.Windows.Forms.TreeNode node)
    {
      foreach (FreeFlow.Administration.Version version in versions)
      {
        // versions
        TreeNode versionNode = TreeNodeFactory.CreateTreeNode(new LibraryVersionAdaptor(version));
        node.Nodes.Add(versionNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 13;
      }
    }

    public override string Text
    {
      get
      {
        return "Versions (" + versions.Count + ")";
      }
    }

    public override Control GetRenderer()
    {
      VersionsControl control = new VersionsControl();
      control.LoadVersions(versions);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override object Object
    {
      get
      {
        return versions;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      versions.Refresh();
    }

    #endregion
  }
}
